home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / System7 tools / Frontier / Frontier SDK 2.1 / Toolkits / Applet Toolkit / appletpopup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-11  |  4.7 KB  |  271 lines  |  [TEXT/KAHL]

  1.  
  2. /*© Copyright 1988-1992 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4.  
  5. #include "appletstrings.h"
  6. #include "appletfont.h"
  7. #include "appletmouse.h"
  8. #include "appletquickdraw.h"
  9. #include "appletops.h"
  10. #include "appletcursor.h"
  11. #include "appletpopup.h"
  12.  
  13.  
  14.  
  15. #define popuparrowwidth 16 
  16.  
  17. #define drawinset 5
  18.  
  19. static short trackericonnum;
  20.  
  21. static Rect trackerrect;
  22.  
  23.  
  24.  
  25.  
  26. boolean pushpopupitem (typopuprecord *popup, bigstring bs, boolean flenabled) {
  27.     
  28.     register MenuHandle hmenu = (*popup).hmenu;
  29.     bigstring bsspace;
  30.     
  31.     if (equalstrings (bs, "\p(-")) /*take disabled seperator as is*/
  32.         AppendMenu (hmenu, bs);
  33.     
  34.     else { /*to allow meta-characters in bs, append blank item, then set item text*/
  35.         
  36.         setstringwithchar (chspace, bsspace);
  37.         
  38.         AppendMenu (hmenu, bsspace);
  39.         
  40.         if (!isemptystring (bs))
  41.             SetItem (hmenu, CountMItems (hmenu), bs);
  42.         }
  43.     
  44.     if (!flenabled)
  45.         DisableItem (hmenu, CountMItems (hmenu));
  46.  
  47.     return (true);
  48.     } /*pushpopupitem*/
  49.     
  50.     
  51. static void displaypopupicon (Rect r, boolean flenabled) {
  52.     
  53.     register short iconnum;
  54.     
  55.     if (flenabled)
  56.         iconnum = 0;
  57.     else
  58.         iconnum = 1;
  59.         
  60.     plotsmallicon (r, 129, iconnum, false);
  61.     } /*displaypopupicon*/
  62.     
  63.     
  64. void drawpopup (typopuprecord *popup) {
  65.     
  66.     Rect rpopup = (*popup).popuprect;
  67.     bigstring bs;
  68.     Rect r;
  69.     RGBColor rgb;
  70.         
  71.     pushbackcolor (whiteindex);
  72.     
  73.     r = rpopup;
  74.     
  75.     r.bottom++;
  76.     
  77.     r.right++;
  78.     
  79.     r = rpopup;
  80.     
  81.     EraseRect (&r);
  82.     
  83.     r = rpopup;
  84.     
  85.     InsetRect (&r, 1, 1);
  86.     
  87.     r.left = r.right - popuparrowwidth;
  88.     
  89.     displaypopupicon (r, true);
  90.     
  91.     r = rpopup;
  92.     
  93.     FrameRect (&r);
  94.     
  95.     MoveTo (r.left + 1, r.bottom);
  96.     
  97.     LineTo (r.right, r.bottom);
  98.     
  99.     LineTo (r.right, r.top + 1);
  100.     
  101.     r.right -= popuparrowwidth;
  102.     
  103.     InsetRect (&r, 4, 2);
  104.     
  105.     pushstyle (geneva, 9, 0);
  106.     
  107.     MoveTo (r.left, r.bottom - globalfontinfo.descent - 1);
  108.     
  109.     copystring ((*popup).bs, bs);
  110.     
  111.     ellipsize (bs, r.right - r.left);
  112.     
  113.     DrawString (bs);
  114.     
  115.     popstyle ();
  116.     
  117.     zerorect (&(*popup).leftarrowrect);
  118.     
  119.     zerorect (&(*popup).rightarrowrect);
  120.     
  121.     if ((*popup).flarrows) {
  122.     
  123.         r = rpopup;
  124.         
  125.         r.right = r.left - drawinset;
  126.         
  127.         r.left = r.right - widthsmallicon;
  128.         
  129.         OffsetRect (&r, 2, 1); /*move it right by two pixels, down by one pixel*/
  130.         
  131.         (*popup).leftarrowrect = r;
  132.         
  133.         plotsmallicon (r, 128, 1, false); 
  134.         
  135.         r = rpopup;
  136.         
  137.         r.left = r.right + drawinset;
  138.         
  139.         r.right = r.left + widthsmallicon;
  140.         
  141.         OffsetRect (&r, -2, 1); /*move it left by two pixels, down by one pixel*/
  142.         
  143.         (*popup).rightarrowrect = r;
  144.         
  145.         plotsmallicon (r, 128, 0, false); 
  146.         }
  147.     
  148.     popbackcolor ();
  149.     } /*drawpopup*/
  150.     
  151.  
  152. static void icontracker (boolean flpressed) {
  153.     
  154.     /*
  155.     callback routine for the mouse tracker.
  156.     */
  157.     
  158.     register short iconnum = trackericonnum;
  159.     
  160.     if (flpressed)
  161.         iconnum += 2;
  162.         
  163.     pushbackcolor (lighterblueindex);
  164.     
  165.     EraseRect (&trackerrect);
  166.     
  167.     plotsmallicon (trackerrect, 128, iconnum, false);
  168.     
  169.     popbackcolor ();
  170.     } /*icontracker*/
  171.     
  172.     
  173. static boolean arrowtracker (Rect r, popupcallback arrowcallback) {
  174.  
  175.     trackerrect = r;
  176.     
  177.     icontracker (true); /*display button in its pressed state*/
  178.     
  179.     if (mousetrack (r, &icontracker)) {
  180.     
  181.         icontracker (false); /*display button in its un-pressed state*/
  182.     
  183.         (*arrowcallback) ();
  184.         }
  185.     
  186.     return (true);
  187.     } /*arrowtracker*/
  188.  
  189.  
  190. boolean popupclick (typopuprecord *popup) {
  191.  
  192.     if (PtInRect (mousestatus.localpt, &(*popup).leftarrowrect)) {
  193.         
  194.         trackericonnum = 1;
  195.     
  196.         arrowtracker ((*popup).leftarrowrect, (*popup).leftarrowcallback);
  197.         
  198.         return (true);
  199.         }
  200.  
  201.     if (PtInRect (mousestatus.localpt, &(*popup).rightarrowrect)) {
  202.         
  203.         trackericonnum = 0;
  204.     
  205.         arrowtracker ((*popup).rightarrowrect, (*popup).rightarrowcallback);
  206.         
  207.         return (true);
  208.         }
  209.         
  210.     if (PtInRect (mousestatus.localpt, &(*popup).popuprect)) {
  211.         
  212.         register MenuHandle hmenu;
  213.         Point pt;
  214.         
  215.         if (!(*popup).getmenucallback ()) /*error, but consume the mouse click*/
  216.             return (true);
  217.         
  218.         hmenu = (*popup).hmenu;
  219.         
  220.         CheckItem (hmenu, (*popup).checkeditem, true);
  221.         
  222.         InsertMenu (hmenu, -1); /*see IM-V, p 236*/
  223.         
  224.         setcursortype (cursorisarrow); /*arrow cursor is more appropriate here*/
  225.         
  226.         pt.v = (*popup).popuprect.top;
  227.         
  228.         pt.h = (*popup).popuprect.left; 
  229.         
  230.         if ((*popup).checkeditem == 0) { /*no item selected*/
  231.             
  232.             CalcMenuSize (hmenu); 
  233.         
  234.             pt.v -= (**hmenu).menuHeight / 2;
  235.             }
  236.             
  237.         LocalToGlobal (&pt); 
  238.         
  239.         pushstyle (geneva, 9, 0);
  240.         
  241.         (*popup).itemselected = LoWord (PopUpMenuSelect (hmenu, pt.v, pt.h, (*popup).checkeditem)); 
  242.         
  243.         popstyle ();
  244.         
  245.         (*popup).menuselectcallback ();
  246.         
  247.         DeleteMenu ((*popup).idmenu);
  248.         
  249.         DisposeMenu (hmenu);
  250.         
  251.         return (true);
  252.         }
  253.     
  254.     return (false);
  255.     } /*popupclick*/
  256.     
  257.  
  258. boolean adjustpopupcursor (typopuprecord *popup) {
  259.     
  260.     if (!PtInRect (mousestatus.localpt, &(*popup).popuprect)) 
  261.         return (false);
  262.     
  263.     setcursortype (cursorispopup);
  264.     
  265.     return (true);
  266.     } /*adjustpopupcursor*/
  267.  
  268.  
  269.  
  270.  
  271.